/*
 *  $Id: Player.cs 1233 2010-12-18 17:54:48Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008-2010 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using Nereal.Serialization;

namespace Ragima {
    /// <summary>
    /// Тип цели: игрок (герой).
    /// </summary>
    public class PlayerTarget : TargetType {
        /// <summary>
        /// Цель: сам игрок.
        /// </summary>
        public static readonly PlayerTarget Own = new PlayerTarget(new Languages.Phrase("target.player.own"), true, false);
        /// <summary>
        /// Цель: вражеский игрок.
        /// </summary>
        public static readonly PlayerTarget Enemy = new PlayerTarget(new Languages.Phrase("target.player.enemy"), false, true);
        /// <summary>
        /// Цель: любой игрок.
        /// </summary>
        public static readonly PlayerTarget Both = new PlayerTarget(new Languages.Phrase("target.player.both"), true, true);

        private bool _own, _enemy;

        public PlayerTarget(Languages.Phrase notice, bool own, bool enemy) : base(notice) {
            _own = own;
            _enemy = enemy;
        }

        public override bool IsRealTarget {
            get { return true; }
        }

        /// <summary>
        /// Число целей равно числу выбранных игроков.
        /// </summary>
        public override int GetCount(AbstractObject caster) {
            return (_own ? 1 : 0) + (_enemy ? 1 : 0);
        }

        public override bool AcceptRegion(Region region) {
            var par = region as PlayerAvatarRegion;
            if (par == null)
                return false;
            return par.Player == Request.Player ? _own : _enemy;
        }

        public override TargetArgs GetArgs(Region region) {
            var par = region as PlayerAvatarRegion;
            return par != null ? new PlayerTargetArgs(Request.Player, Request.Caster, par.Player) : null;
        }
    }

    [TypeId("player")]
    public class PlayerTargetArgs : TargetArgs<Player> {
        [Serialize, XmlName("target"), Reference(true, typeof(bool), Serialization.Resolvers.GamePlayer)]
        private Player _target;

        public PlayerTargetArgs() {
        }
        public PlayerTargetArgs(Player player, AbstractObject caster, Player target) : base(player, caster) {
            _target = target;
        }

        public override Player Target {
            get { return _target; }
        }
    }
}
